<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
    <style>
        [v-cloak]{
            display: none;
        }
        .product{
            background-color: orange;
        }
    </style>
</head>
<body>
<div id="app" v-cloak>
    <home-nav></home-nav>
    <product-item></product-item><hr/>
    <product-item></product-item><hr/>
    <product-item></product-item><hr/>
</div>

<template id="nav">
    <h2>我是导航</h2>
</template>

<template id="product">
    <div class="product">
        <h2>{{title}}</h2>
        <p>商品描述，限时折扣，赶紧抢购</p>
        <p>价格：{{price}}</p>
        <button v-on:click="favarItem">收藏</button>
    </div>
</template>

<script src="https://unpkg.com/vue@3"></script>
<script>
    const app=Vue.createApp({
        data(){
            return{
                message:'hello world'
            }
        }
    })

    app.component('home-nav',{
        template:'#nav'
    })

    app.component('product-item',{
        template:'#product',
        data(){
            return{
                title:'产品标题',
                price:998,
            }
        },
        methods:{
            favarItem(){
                console.log("点击了收藏")
            }
        }
    })

    app.mount("#app")
</script>
</body>
</html>